<?php
namespace app\admin\controller;

use think\Request;
use app\admin\model\Channel;

class Analyze extends Common
{
    //统计分析
    public function stats(Request $request)
    {
        $where = [];
        if ($request->param('courses_title')) {
            $where['courses_title'] = $request->param('courses_title', '', 'trim');
            $this->assign('courses_title', $where['courses_title']);
        }
        if ($request->param('starttime') && $request->param('endtime')) {
            $starttime = $request->param('starttime', '', 'trim');
            $endtime = $request->param('endtime', '', 'trim');
            $where['create_time'] = ['between', [
                strtotime($starttime),
                strtotime($endtime) + 86400,
            ]];
            $this->assign('starttime', $starttime);
            $this->assign('endtime', $endtime);
        } elseif ($request->param('starttime')) {
            $starttime = $request->param('starttime', '', 'trim');
            $where['create_time'] = [
                'egt',
                strtotime($starttime),
            ];
            $this->assign('starttime', $starttime);
        } elseif ($request->param('endtime')) {
            $endtime = $request->param('endtime', '', 'trim');
            $where['create_time'] = [
                'elt',
                strtotime($endtime) + 86400,
            ];
            $this->assign('endtime', $endtime);
        }
        $channelModel = new Channel();
        $data = $channelModel->stats($where);
        $this->assign('data', $data);
        return $this->fetch();
    }
}